from python.db.http import fetch

# basic


def _uuid():
    return fetch('uuid')


def _types():
    return fetch('types')


def _show_primary_key():
    return fetch('showPrimaryKey')

# column


def _has_column(table_name, column_name):
    return fetch('hasColumn', {
        'tableName': table_name,
        'columnName': column_name
    })


def _drop_column(table_name, column_name):
    return fetch('dropColumn', {
        'tableName': table_name,
        'columnName': column_name
    })


def _add_column(table_name, column):
    return fetch('addColumn', {
        'tableName': table_name,
        'column': column
    })


def _rename_column(table_name, column):
    return fetch('renameColumn', {
        'tableName': table_name,
        'column': column
    })


def _show_columns(table_name, include_primary_key=False):
    return fetch('show_columns', {
        'tableName': table_name,
        'includePrimaryKey': include_primary_key
    })

# table


def _show_tables():
    return fetch('showTables')


def _has_table(table_name):
    return fetch('hasTable', {
        'tableName': table_name
    })


def _drop_table(table_name):
    return fetch('dropTable', {
        'tableName': table_name
    })


def _truncate_table(table_name):
    return fetch('truncateTable', {
        'tableName': table_name
    })


def _rename_table(from_table_name, to_table_name):
    return fetch('renameTable', {
        'fromTableName': from_table_name,
        'toTableName': to_table_name
    })


def _create_table(table_name, data):
    return fetch('create_table', {
        'tableName': table_name,
        'data': data
    })


# write

def _insert_handler(table_name, data):
    return fetch('insertHandler', {
        'tableName': table_name,
        'data': data
    })


def _update_handler(table_name, where, data):
    return fetch('updateHandler', {
        'tableName': table_name,
        'where': where,
        'data': data
    })


def _delete_handler(table_name, where):
    return fetch('deleteHandler', {
        'tableName': table_name,
        'where': where
    })


def _update_by_id_handler(table_name, data):
    return fetch('updateByIdHandler', {
        'tableName': table_name,
        'data': data
    })


def _save_handler(table_name, data):
    return fetch('saveHandler', {
        'tableName': table_name,
        'data': data
    })


def _delete_by_id_handler(table_name, _id):
    return fetch('saveHandler', {
        'tableName': table_name,
        'id': _id
    })

# read


def _select_handler(table_name, methods):
    return fetch('selectHandler', {
        'tableName': table_name,
        'methods': methods
    })


def _select_where_handler(table_name, where):
    return fetch('selectWhereHandler', {
        'tableName': table_name,
        'where': where
    })


# read


def _page_handler(table_name, page):
    return fetch('pageHandler', {
        'tableName': table_name,
        'page': page
    })
